package com.dailyblue.java.spring.boot.mvc.mybatis.controller;

import com.dailyblue.java.spring.boot.commons.bean.Post;
import com.dailyblue.java.spring.boot.commons.util.JsonResult;
import com.dailyblue.java.spring.boot.mvc.mybatis.service.PostService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/post")
public class PostController {
    @Resource
    private PostService postService;

    @RequestMapping("/id")
    @ResponseBody
    public JsonResult find(int id) {
        return postService.findPostById(id);
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public JsonResult save(Post post, HttpServletRequest request) {
        return postService.savePost(post, request.getHeader("token"));
    }
}
